package com.muse.sentinel.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;

@RestController
public class SentinelNacosDemoController {

    /**
     * 案例1：编码方式接入spring-cloud-alibaba-sentinel
     * http://localhost:8001/foo1
     */
    @SentinelResource(value = "foo1", blockHandler = "blockHandlerFoo1")
    @GetMapping("/foo1")
    public String foo1() {
        return "-----foo1-----";
    }
    public String blockHandlerFoo1(BlockException e) {
        return "request blocking!";
    }

    /**
     * 案例2：接入sentinel dashboard，来配置限流规则
     * http://localhost:8001/dashboard
     */
    @GetMapping("/dashboard")
    public String dashboard() {
        return "-----dashboard-----";
    }

    /**
     * 案例3：URL资源清洗
     * http://localhost:8001/urlCleaner/1和http://localhost:8001/urlCleaner/2
     */
    @GetMapping("/urlCleaner/{id}")
    public String urlCleaner(@PathVariable("id") int id) {
        return "-----urlCleaner-----";
    }

    /**
     * 案例4：集成nacos
     * http://localhost:8001/withnacos
     */
    @GetMapping("/withnacos")
    public String withnacos() {
        return "-----withnacos-----";
    }
}
